#include "wxsfilepickerctrl.h"

#include <wx/filepicker.h>

namespace {
  wxsRegisterItem<wxsFilePickerCtrl> Reg( _T( "FilePickerCtrl" ), _T( "文件控件" ), wxsTWidget, _T( "对话框" ), 110 );
  WXS_ST_BEGIN( wxsFilePickerCtrlStyles, _T( "wxFLP_OPEN|wxFLP_FILE_MUST_EXIST" ) )
  WXS_ST_CATEGORY( "wxFilePickerCtrl" )
  WXS_ST( wxFLP_CHANGE_DIR )
  WXS_ST( wxFLP_FILE_MUST_EXIST )
  WXS_ST( wxFLP_OPEN )
  WXS_ST( wxFLP_OVERWRITE_PROMPT )
  WXS_ST( wxFLP_SAVE )
  WXS_ST( wxFLP_USE_TEXTCTRL )
  WXS_ST_END()
  WXS_EV_BEGIN( wxsFilePickerCtrlEvents )
  WXS_EVI( EVT_FILEPICKER_CHANGED, wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEvent, FileChanged )
  WXS_EV_END()
}

wxsFilePickerCtrl::wxsFilePickerCtrl( wxsItemResData* Data ):
  wxsWidget(
    Data,
    &Reg.Info,
    wxsFilePickerCtrlEvents,
    wxsFilePickerCtrlStyles ),
  m_sMessage( wxFileSelectorPromptStr ),
  m_sPath( wxEmptyString ),
  m_sWildcard( wxFileSelectorDefaultWildcardStr ) {}


void wxsFilePickerCtrl::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/filepicker.h>" ), GetInfo().ClassName, 0 );
      Codef( _T( "%C(%W, %I, %n, %t, %n, %P, %S, %T, %V, %N);\n" ), m_sPath.wx_str(), m_sMessage.wx_str(), m_sWildcard.wx_str() );
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsFilePickerCtrl::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}


wxObject* wxsFilePickerCtrl::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxFilePickerCtrl* Preview;
  Preview = new wxFilePickerCtrl( Parent, GetId(), m_sPath, m_sMessage, m_sWildcard, Pos( Parent ), Size( Parent ), Style() );
  return SetupWindow( Preview, Flags );
}


void wxsFilePickerCtrl::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_SHORT_STRING( wxsFilePickerCtrl, m_sMessage, _T( "Message" ), _T( "message" ), wxFileSelectorPromptStr, false )
  WXS_SHORT_STRING( wxsFilePickerCtrl, m_sPath, _T( "Path" ), _T( "path" ), wxEmptyString, false )
  WXS_SHORT_STRING( wxsFilePickerCtrl, m_sWildcard, _T( "Wildcard" ), _T( "wildcard" ), wxFileSelectorDefaultWildcardStr, false )
}
